% Copyright (C) 2009,2010,2011,2012  Marco Restelli
%
% This file is part of:
%   LDGH -- Local Hybridizable Discontinuous Galerkin toolkit
%
% LDGH is free software: you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% LDGH is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
% License for more details.
%
% You should have received a copy of the GNU General Public License
% along with LDGH. If not, see <http://www.gnu.org/licenses/>.
%
% author: Marco Restelli                   <marco.restelli@gmail.com>


function pet2metis (p, e, t, d, filename)
  
  fid = fopen (filename, "w");
  if (fid >= 0)
    fprintf (fid, "%d\n", columns(t));
    if (d == 3)
      fprintf (fid, "%d %d %d %d\n", t(1:4, :));
    elseif (d == 2)
      fprintf (fid, "%d %d %d\n", t(1:3, :));
    else
      error (["pet2metis: can only be used for 2d or 3d "...
	      "meshes of simplices"])
    endif
  else
    error (["pet2metis: could not"...
	    " open file %s for writing"], 
	   filename)
  endif
  fclose (fid);
  
endfunction
